<?php

header("Content-type: text/html; charset=utf-8"); 
/**
* 新闻控制器
*/
class News extends CI_Controller
{
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		parent::__construct();
		$this->load->model('news_model');
		$this->load->helper(array('form','url'));
		$this->load->library('form_validation');
	}
	/**
	 * 默认视图，加载新闻列表
	 */
	public function index()
	{
		
		$data['news']=$this->news_model->get_news();
		$data['title']='News Archive';
		$this->load->view('templates/header',$data);
		$this->load->view('news/index',$data);
		$this->load->view('templates/footer',$data);
	}

	/**
	 * 新闻详情视图
	 * @param $id 新闻查询条件
	 */
	public function view($id)
	{
		$data['news_items']=$this->news_model->get_news($id);
		$data['title']='News Context';
		$this->load->view('templates/header',$data);
		$this->load->view('news/view',$data);
		$this->load->view('templates/footer',$data);
	}
	/**
	 * 新建新闻视图
	 */
	public function create()
	{
		
		$data['title']='Create a News Items';
		$this->form_validation->set_rules('title','Title','required');
		$this->form_validation->set_rules('text','text','required');
		if ($this->form_validation->run() === FALSE) {
			$this->load->view('templates/header',$data);
			$this->load->view('news/create');
			$this->load->view('templates/footer');
		}else{
			$this->news_model->set_news();
			$this->load->view('news/success');
		}
	}

	public function get_ajax_pages($pagesize=10 , $page=1)
	{
		echo "当前第".$page."页，每页显示：".$pagesize."条数据！";
	}

	/**
	 * 公共函数测试
	 */
	public function test_common_function()
	{
		//测试is_php($param);函数，判断系统PHP版本是否符合系统要求
		if (is_php('5.3.0')) {
			echo "当前主机安装的PHP版本高于系统要求版本!";
		}else{
			echo "当前主机安装的PHP版本低于系统要求版本!";
		}
		echo "<br/>";
		//测试is_reallu_writable('path/to/file');函数，判断是否有写的权限
		if (is_really_writable('file.txt'))
		{
			echo "I could write to this if I wanted to";
		}
		else
		{
			echo "File is not writable";
		}


	}
}